package com.hl.learndagger.presenter;


import com.hl.learndagger.ISearchBalance;
import com.hl.learndagger.model.SearchBalanceModel;
import com.hl.learndagger.model.SearchCallBack;

public class SearchPresenter {
    private ISearchBalance iLoginView;
    private SearchBalanceModel searchBalanceModel;

    public SearchPresenter(ISearchBalance iLoginView, SearchBalanceModel searchBalanceModel) {
        this.iLoginView = iLoginView;
        this.searchBalanceModel = searchBalanceModel;
    }

    public void login(String number,String password)
    {
        //检查
        if (number == null) iLoginView.searchFailure("号码为空！");

        //调loginModel登录
        searchBalanceModel.searchBalance(number, new SearchCallBack() {
            @Override
            public void onSuccess(int balance) {
                //做某些事情

                //更新UI
                if (iLoginView != null) iLoginView.searchSuccessful(balance);
            }

            @Override
            public void onFailed(int responseCode, String errorMsg) {

                if (iLoginView != null)iLoginView.searchFailure(errorMsg);
            }
        });
    }
}
